package com.zkingsoft.rhi.config;

import com.zkingsoft.rhi.interceptor.LoginHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//应为类型要求为WebMvcConfigurer，所以我们实现其接口
//可以使用自定义类扩展MVC的功能
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Bean
    public LoginHandlerInterceptor loginHandlerInterceptor(){
        return new LoginHandlerInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        //paramInterceptor()是一个参数拦截器拦截 /api/接口的参数
        registry.addInterceptor(loginHandlerInterceptor()).addPathPatterns("/**")
        .excludePathPatterns("/login/login","/excel/exportImmovableExcel",
                "/excel/exportMovableExcel","/excel/exportDetailedImmovableExcel",
                "/excel/exportDetailedImmovableExcelById","/excel/exportImmovableExcelById");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}